const mongoose = require('../common/db');

const cart = new mongoose.Schema({
  username: String,
  goodsId: String,
  goodsCount: Number
});

// 通过用户名查找
cart.statics.findByUsername = function (username, callBack) {
  this.find({ username: username }, callBack);
};

// 通过商品名查找
cart.statics.findByGoodsId = function (goodsId, callBack) {
  this.findOne({ goodsId: goodsId }, callBack);
};

const cartModel = mongoose.model('cart', cart);
module.exports = cartModel;